package designPattern.structure7.Adapter.chapter8_adapter.test8_2;

public class Application {
    public static void main(String args[]) {

        ThreeElectricOutlet threeOutlet;        //三相插座
        TwoElectricOutlet twoOutlet;           //两相插座
        Wash wash = new Wash();              //洗衣机
        TV tv = new TV();                     //电视机

//        System.out.println("--------单向适配器---------");
//
//       threeOutlet=wash;                       //洗衣机插在三相插座上
//       System.out.println("使用三相插座接通电流：");
//       threeOutlet.connectElectricCurrent();   //接通电流，开始洗衣服
//
//       TreeElectricAdapter adapter=new  TreeElectricAdapter(tv);//把电视插在适配器上
//       threeOutlet=adapter;                    //适配器插在三相插座上
//       System.out.println("使用三相插座接通电流：");
//       threeOutlet.connectElectricCurrent();   //接通电流，开始播放电视节目

        System.out.println("--------双向适配器---------");

        TreeAndTwoElectricAdapter adapter2 = new TreeAndTwoElectricAdapter(tv, wash);

        threeOutlet = adapter2;
        threeOutlet.connectElectricCurrent();
//
//        twoOutlet=adapter2;
//        twoOutlet.connectElectricCurrent();

    }
}

class Wash implements ThreeElectricOutlet { //洗衣机使用三相插座
    String name;

    Wash() {
        name = "黄河洗衣机";
    }

    Wash(String s) {
        name = s;
    }

    public void connectElectricCurrent() {
        turnOn();
    }

    public void turnOn() {
        System.out.println(name + "开始洗衣物。");
    }
}

class TV implements TwoElectricOutlet {    //电视机使用两相插座
    String name;

    TV() {
        name = "长江电视机";
    }

    TV(String s) {
        name = s;
    }

    public void connectElectricCurrent() {
        turnOn();
    }

    public void turnOn() {
        System.out.println(name + "开始播放节目。");
    }
}